package com.dengqi.mymodule.activity.loader.album;

import android.Manifest;
import android.database.Cursor;
import android.os.Bundle;

import com.dengqi.mymodule.BaseActivity;
import com.dengqi.mymodule.R;
import com.tbruyelle.rxpermissions2.RxPermissions;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.functions.Consumer;

/**
 *
 */
public class LoaderAlbumActivity extends BaseActivity implements AlbumCollection.AlbumCallbacks {


    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private AlbumCollection mCollection;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loader_recycler);
        ButterKnife.bind(this);


        new RxPermissions(this)
                .request(Manifest.permission.READ_EXTERNAL_STORAGE)
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        mCollection = new AlbumCollection();
                        mCollection.init(LoaderAlbumActivity.this, LoaderAlbumActivity.this);
                    }
                });

    }


    @Override
    public void onAlbumLoad(Cursor cursor) {
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(new AlbumAdapter(cursor));
        mCollection.destroyLoader();
    }

    @Override
    public void onAlbumReset() {

    }
}
